﻿using System;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using O1.Kernel.Primitives;
using O1.Kernel;

namespace Tests.O1.Kernel.Primitives
{
    [TestClass]
    public class ParsingExtensionsTests
    {
        [TestMethod, TestCategory("Unit Test")]
        public void ConversionExtensionsToDateTimeWorksAsExpected()
        {
            DateTime expected = new DateTime(1999, 12, 31);
            var buffer = new byte[Sz.CLR.DateTime];
            expected.CopyBytes(buffer, 0);

            var actual = buffer.ToDateTime(0);
            actual.Should().Be(expected);
        }

        [TestMethod, TestCategory("Unit Test")]
        public void ConversionExtensionsToDateTimeOffsetWorksAsExpected()
        {
            DateTimeOffset expected = new DateTimeOffset(1999, 12, 31, 23, 59, 59, TimeSpan.Zero);
            var buffer = new byte[Sz.CLR.DateTimeOffset];
            expected.CopyBytes(buffer, 0);

            var actual = buffer.ToDateTimeOffset(0);
            actual.Should().Be(expected);
        }

        [TestMethod, TestCategory("Unit Test")]
        public void ConversionExtensionsToDecimalWorksAsExpected()
        {
            decimal expected = 1099245.876m;
            var buffer = new byte[Sz.CLR.Decimal];
            expected.CopyBytes(buffer, 0);

            var actual = buffer.ToDecimal(0);
            actual.Should().Be(expected);
        }

        [TestMethod, TestCategory("Unit Test")]
        public void ConversionExtensionsToGuidWorksAsExpected()
        {
            Guid expected = Guid.NewGuid();
            var buffer = new byte[Sz.CLR.Guid];
            expected.CopyBytes(buffer, 0);

            var actual = buffer.ToGuid(0);
            actual.Should().Be(expected);
        }

        [TestMethod, TestCategory("Unit Test")]
        public void ConversionExtensionsToHashGuidIsValueConsistent()
        {
            "TEST1".ToHashGuid().Should().Be("TEST1".ToHashGuid());
            "TEST1".ToHashGuid().Should().NotBe("test1".ToHashGuid());
        }

        [TestMethod, TestCategory("Unit Test")]
        public void ConversionExtensionsToHashGuidIsEmptyForStringEmpty()
        {
            string.Empty.ToHashGuid().Should().Be(Guid.Empty);
        }

        [TestMethod, TestCategory("Unit Test")]
        public void ConversionExtensionsToHashGuidIsEmptyForNullString()
        {
            string value = null;
            value.ToHashGuid().Should().Be(Guid.Empty);
        }
    }
}
